<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Profiles extends CI_Controller {

    var $member_id;

    public function __construct() {
        parent::__construct();
        $this->load->library('auth');
        $this->auth->restrict();

        $this->load->helper('text');
        $this->load->model('m_member');

        $this->member_id = $this->session->userdata('member_id');
    }

    public function index($message = NULL) {
//        $data['title'] = $this->lang->line('profile') . ' ' . $this->lang->line('webname');
//        $data['message'] = $message;

        $this->edit($message);
    }

    function edit($message = NULL) {
        $this->form_validation->set_error_delimiters('<div class="alert alert-warning">', '</div>');
        $this->form_validation->set_rules('in_p_namanya', $this->lang->line('namanya'), 'trim|required');
        $this->form_validation->set_rules('in_p_email', $this->lang->line('email'), 'trim|required|valid_email');
        $this->form_validation->set_rules('in_p_status', $this->lang->line('status'), 'trim|required');

        if ($this->form_validation->run() == FALSE) {
            $aktifs = array($this->lang->line('nonaktif'), $this->lang->line('aktif'));

//            $data = $this->auth->load_style();
//            $data['sm_profile'] = 'active';
            $data['title'] = $this->lang->line('profile') . ' ' . $this->lang->line('webname');
            $data['aktifs'] = $aktifs;
            $data['profiles'] = $this->m_member->get_by_id($this->session->userdata('member_id'));
            $data['message'] = $message;

            $this->load->view('view_header', $data);
            $this->load->view('profile_view', $data);
            $this->load->view('view_footer', $data);
        } else {
            $this->m_member->member_namanya = $this->input->post('in_p_namanya');
            $this->m_member->member_email = $this->input->post('in_p_email');
            $this->m_member->member_status = $this->input->post('in_p_status');

            $this->m_member->member_id = $this->session->userdata('member_id');
            $this->m_member->save();

            //$this->index('');
            redirect('homes/');
        }
    }

    function pass($message = NULL) {
        $this->form_validation->set_error_delimiters('<div class="alert alert-warning">', '</div>');
        $this->form_validation->set_rules('in_p_pass', $this->lang->line('pass'), 'trim|required|min_length[4]|matches[in_p_pass2]');
        $this->form_validation->set_rules('in_p_pass2', $this->lang->line('pass2'), 'trim|required|min_length[4]');

        if ($this->form_validation->run() == FALSE) {
//            $data = $this->auth->load_style();
//            $data['sm_profile'] = 'active';
            $aktifs = array($this->lang->line('nonaktif'), $this->lang->line('aktif'));
            $data['title'] = $this->lang->line('rubah_pass') . ' ' . $this->lang->line('profile');
            $data['aktifs'] = $aktifs;
            $data['profiles'] = $this->m_member->get_by_id($this->session->userdata('member_id'));
            $data['message'] = $message;

            $this->load->view('view_header', $data);
            $this->load->view('profile_view', $data);
            $this->load->view('view_footer', $data);
        } else {
            $this->m_member->member_pass = $this->input->post('in_p_pass');

            $this->m_member->member_id = $this->session->userdata('member_id');
            $this->m_member->save();

            //$this->index('');
            redirect('homes/');
        }
    }

}

/* End of file profiles.php */
/* Location: ./application/controllers/profiles.php */